package com.jxdinfo.hussar.cloud.module.example.lift.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jxdinfo.hussar.cloud.module.example.lift.dto.LiftNoticeSearchDto;
import com.jxdinfo.hussar.cloud.module.example.lift.model.LiftNotice;
import com.jxdinfo.hussar.cloud.module.example.lift.service.LiftNoticeService;
import com.jxdinfo.hussar.engine.metadata.model.BaseEntity;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 升降机异常通知(LiftNotice)表控制层
 *
 * @author makejava
 * @since 2023-10-23 18:28:35
 */
@RestController
@RequestMapping("liftNotice")
public class LiftNoticeController   {
    /**
     * 服务对象
     */
    @Resource
    private LiftNoticeService liftNoticeService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param liftNotice 查询实体
     * @return 所有数据
     */
    @GetMapping
    public ApiResponse selectAll(Page<LiftNotice> page, LiftNotice liftNotice) {
        return ApiResponse.success(this.liftNoticeService.page(page, new QueryWrapper<>(liftNotice)));
    }

    /**
     * 预警报警通知
     * @param liftNoticeSearchDto
     * @return
     */
    @PostMapping("/findByPage")
    public ApiResponse<Page<LiftNotice>> findByPage(LiftNoticeSearchDto liftNoticeSearchDto) {

        if(ObjectUtils.isNotEmpty(liftNoticeSearchDto.getTyProjectCode())){
            liftNoticeSearchDto.setTyProjectCode(liftNoticeSearchDto.getTyProjectCode());
        }else{
          //  liftNoticeSearchDto.setTyProjectCode(ProjectUtil.getProjectInfo().getProjectCode());
        }

        Page<LiftNotice> pageResult = liftNoticeService.findPage(liftNoticeSearchDto);
        //ResultData<PageResult<LiftNoticeDto>> result = this.convertToDtoPageResult(pageResult);
        return ApiResponse.success(pageResult);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ApiResponse selectOne(@PathVariable Serializable id) {
        return ApiResponse.success(this.liftNoticeService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param liftNotice 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ApiResponse insert(@RequestBody LiftNotice liftNotice) {
        return ApiResponse.success(this.liftNoticeService.save(liftNotice));
    }

    /**
     * 修改数据
     *
     * @param liftNotice 实体对象
     * @return 修改结果
     */
    @PutMapping
    public ApiResponse update(@RequestBody LiftNotice liftNotice) {
        return ApiResponse.success(this.liftNoticeService.updateById(liftNotice));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ApiResponse delete(@RequestParam("idList") List<Long> idList) {
        return ApiResponse.success(this.liftNoticeService.removeByIds(idList));
    }
}

